import request from "@/utils/request";
import type {
  AddOrUpdateSkuParams,
  SkuList,
  GetSkuListApiResponse,
} from "./model/skuModel";
enum Api {
  addSku = "/admin/product/saveSkuInfo",
  getSkuListBySpuId = "/admin/product/findBySpuId",
  getSkuList = "/admin/product/list",
  getOnSale = "/admin/product/onSale",
  getCancelSale = "/admin/product/cancelSale",
  getSkuById = "/admin/product/getSkuById",
}
/**
 * 添加sku
 * @param data AddOrUpdateSkuParams
 * @returns null
 */
export const addSkuApi = (data: AddOrUpdateSkuParams) => {
  return request.post<any, null>(Api.addSku, data);
};

/**
 * 通过spuId获取skuList
 * @param spuId
 * @returns SkuList
 */
export const getSkuListBySpuIdApi = (spuId: number) => {
  return request.get<any, SkuList>(Api.getSkuListBySpuId + `/${spuId}`);
};
/**
 * 分页获取skuList
 * @param page 页码
 * @param limit 每页条数
 * @returns GetSkuListApiResponse
 */
export const getSkuListApi = (page: number, limit: number) => {
  return request.get<any, GetSkuListApiResponse>(
    Api.getSkuList + `/${page}/${limit}`
  );
};
// 上架
export const getOnSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.getOnSale + `/${skuId}`);
};
// 下架
export const getCancelSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.getCancelSale + `/${skuId}`);
};

/**
 * 通过skuId获取sku详情
 * @param skuId 
 * @returns AddOrUpdateSkuParams
 */
export const getSkuByIdApi = (skuId: number) => {
  return request.get<any, AddOrUpdateSkuParams>(Api.getSkuById + `/${skuId}`);
};
